import { get, post, put, del } from '@/utils/request';
import type { ApiResponse, SysUser } from '@/types/api';
import type { PageParams, PageResult } from '@/types/common';

export function userList(params?: PageParams & { username?: string; phone?: string; lockFlag?: boolean }) {
  return get<ApiResponse<PageResult<SysUser>>>('/user/list', { params });
}

export function userGet(userId: number) {
  return get<ApiResponse<SysUser>>(`/user/${userId}`);
}

export function userAdd(body: SysUser) {
  return post<ApiResponse<string>>('/user/add', body);
}

export function userUpdate(body: SysUser) {
  return put<ApiResponse<string>>('/user/update', body);
}

export function userDelete(userId: number) {
  return del<ApiResponse<string>>(`/user/delete/${userId}`);
}

export function userAssignRoles(userId: number, roleIdList: number[]) {
  return post<ApiResponse<string>>(`/user/${userId}/roles`, roleIdList);
}

export function userResetPassword(userId: number) {
  return post<ApiResponse<string>>(`/user/${userId}/resetPassword`);
}

export function userChangePassword(oldPassword: string, newPassword: string) {
  return put<ApiResponse<string>>('/user/changePassword', { oldPassword, newPassword });
}